package com.kyw.android_dev_util.interceptor;

import com.kyw.android_dev_util.common.ConstField;
import com.kyw.android_dev_util.common.MessageConstant;
import com.kyw.android_dev_util.exception.BizException;
import org.springframework.beans.BeanUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CommonInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String project_path = request.getHeader("PROJECT_PATH");
        String from_type = request.getHeader("FROM_TYPE");
        if("PC".equals(from_type)){
            if(project_path == null){
                throw new BizException(MessageConstant.ACCESS_FAILED,"请在全局中设置项目的根路径");
            }else {
                ConstField.PROJECT_PATH = project_path;
                ConstField.LAYOUT_PATH = project_path + "\\app\\src\\main\\res\\layout\\";
            }
        }
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        System.out.println("================= jin ru  after ===============");
    }
}
